﻿using CatUtils.Utils.Currency.IoUtils;

using CatUtils.Utils.SpecialUtils.View;
using CatUtilsDll.Utils.Currency.WebUtils;
using RabbitDownload.WebSite.Pixiv.Login;
using System;
using System.Windows.Forms;

namespace RabbitDownload.WebSite.Pixiv.ClearData
{
    public partial class ClearControl : UserControl
    {
        public ClearControl()
        {
            InitializeComponent();
            InitView();
        }

        private void InitView()
        {
            Groupboxhelper.Replace(groupBox1, new Login.LoginControl());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (new LoginHelper().AutoLogin() == null)
            {
                Console.WriteLine("登录失败");
                return;
            }
        }

        private string ExcludeKeysPath = "";

        private void button20_Click(object sender, EventArgs e)
        {
            ExcludeKeysPath = FileHelper.SelectFile();
            label3.Text = string.Format("当前加载词库：{0}", FileNameHelper.GetFileNameWithoutExtension(ExcludeKeysPath));
        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (!StartFlag())
            {
                return;
            }
            CWebclient cWebclient = new LoginHelper().AutoLogin();
            if (new LoginHelper().AutoLogin() == null)
                return;
            new ClearWithLst().HandleLst(FileHelper.SelectFile(), ExcludeKeysPath, cWebclient);
        }

        private void button19_Click(object sender, EventArgs e)
        {
            if (!StartFlag())
            {
                return;
            }
            CWebclient cWebclient = new LoginHelper().AutoLogin();
            if (new LoginHelper().AutoLogin() == null)
                return;
            new ClearWithLst().HandleLstFloder(FloderHelper.SelectFloder(), ExcludeKeysPath, cWebclient);
        }

        /// <summary>
        /// 用于判断程序是否可以启动
        /// </summary>
        /// <returns></returns>
        private bool StartFlag()
        {
            if (ExcludeKeysPath == "")
            {
                Console.WriteLine("未选择词库");
                return false;
            }

            if (new LoginHelper().AutoLogin() == null)
            {
                Console.WriteLine("登录失败");
                return false;
            }
            return true;
        }
    }
}